snapshot: Always create an initial node
authorBenjamin Otte <otte@redhat.com>
Fri, 9 Dec 2016 20:33:38 +0000 (21:33 +0100)
committerBenjamin Otte <otte@redhat.com>
Fri, 9 Dec 2016 20:39:43 +0000 (21:39 +0100)
This way we ensure that there is only one root node and everybody can
append() with impunity.

gtk/gtksnapshot.c
gtk/gtksnapshotprivate.h
gtk/gtkwidget.c

index a037e727686cefd29c9ff17dc8943c5c293dda3b..c7c2bd3214f55172b825da00cad6535009d54bfc 100644 (file)
@@ -99,17 +99,42 @@ gtk_snapshot_state_get_world_transform (GtkSnapshotState *state)
 void
 gtk_snapshot_init (GtkSnapshot          *snapshot,
                    GskRenderer          *renderer,
-                   const cairo_region_t *clip)
+                   const cairo_region_t *clip,
+                   const char           *name,
+                   ...)
 {
+  cairo_rectangle_int_t extents;
+
+  cairo_region_get_extents (clip, &extents);
+
   snapshot->state = NULL;
-  snapshot->root = NULL;
   snapshot->renderer = renderer;
   snapshot->clip_region = clip;
+  snapshot->root = gsk_renderer_create_render_node (renderer);
+  gsk_render_node_set_bounds (snapshot->root, &GRAPHENE_RECT_INIT (extents.x, extents.y, extents.width, extents.height));
+
+  if (name)
+    {
+      va_list args;
+      char *str;
+
+      va_start (args, name);
+      str = g_strdup_vprintf (name, args);
+      va_end (args);
+
+      gsk_render_node_set_name (snapshot->root, str);
+
+      g_free (str);
+    }
+
+  snapshot->state = gtk_snapshot_state_new (NULL, snapshot->root);
 }
 
 GskRenderNode *
 gtk_snapshot_finish (GtkSnapshot *snapshot)
 {
+  gtk_snapshot_pop (snapshot);
+
   if (snapshot->state != NULL)
     {
       g_warning ("Too many gtk_snapshot_push() calls.");
@@ -305,10 +330,6 @@ gtk_snapshot_append_node (GtkSnapshot   *snapshot,
       gsk_render_node_append_child (snapshot->state->node, node);
       gsk_render_node_set_transform (node, &snapshot->state->transform);
     }
-  else if (snapshot->root == NULL)
-    {
-      snapshot->root = gsk_render_node_ref (node);
-    }
   else
     {
       g_critical ("Tried appending a node to an already finished snapshot.");
index ff9d1b62c0dc2605ec3a8b1fe14498f26c3eaa62..2f7096287faa9fb5dfa4705f2ea5ea9f20b64b00 100644 (file)
@@ -44,7 +44,9 @@ struct _GtkSnapshot {
 
 void            gtk_snapshot_init               (GtkSnapshot             *state,
                                                  GskRenderer             *renderer,
-                                                 const cairo_region_t    *clip);
+                                                 const cairo_region_t    *clip,
+                                                 const char              *name,
+                                                 ...) G_GNUC_PRINTF (4, 5);
 GskRenderNode * gtk_snapshot_finish             (GtkSnapshot             *state);
 
 static inline const graphene_matrix_t *
index 168bdf669cbbc1f8834ebf27a4ca9f7340cc7ce4..162d67ae0c99ec384c5c26f359b23294f655ca8e 100644 (file)
@@ -6338,7 +6338,7 @@ gtk_widget_draw_internal (GtkWidget *widget,
                                                 widget->priv->clip.width,
                                                 widget->priv->clip.height});
           fallback = gsk_renderer_create_fallback (renderer, &viewport, cr);
-          gtk_snapshot_init (&snapshot, renderer, clip);
+          gtk_snapshot_init (&snapshot, renderer, clip, "Fallback<%s>", G_OBJECT_TYPE_NAME (widget));
           gtk_widget_snapshot (widget, &snapshot);
           node = gtk_snapshot_finish (&snapshot);
           if (node != NULL)
@@ -15623,7 +15623,8 @@ gtk_widget_render (GtkWidget            *widget,
 
   gtk_snapshot_init (&snapshot,
                      renderer,
-                     gdk_drawing_context_get_clip (context));
+                     gdk_drawing_context_get_clip (context),
+                     "Render<%s>", G_OBJECT_TYPE_NAME (widget));
   gtk_widget_snapshot (widget, &snapshot);
   root = gtk_snapshot_finish (&snapshot);
   if (root != NULL)